package com.tt.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tt.entity.pojo.MovieInfoTypePO;
import com.tt.service.MovieInfoTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 电影分类表,主要是搜索使用 前端控制器
 * </p>
 *
 * @author TP
 * @since 2023-03-04 09:14:11
 */
@RestController
public class MovieInfoTypeController {

    private final MovieInfoTypeService movieInfoTypeServiceImpl;

    public MovieInfoTypeController(MovieInfoTypeService movieInfoTypeServiceImpl) {
        this.movieInfoTypeServiceImpl = movieInfoTypeServiceImpl;
    }

    @GetMapping("/types")
    public List<String> getMovieTypes() {
        QueryWrapper<MovieInfoTypePO> wrapper = new QueryWrapper<>();
        // DISTINCT直接写select里, 并且查询多个字段可以由"id","name"改为"id, name"
        // 按type排序是为了保证类型的顺序基本固定
        wrapper.select("DISTINCT type").orderByDesc("type");

        List<MovieInfoTypePO> result = movieInfoTypeServiceImpl.list(wrapper);
        return result.stream().map(MovieInfoTypePO::getType).collect(Collectors.toList());
    }
}
